<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/common/common.jspf" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>test</title>

</head>
 <script>
     $(document).ready(function(){
            //初始化读取所有订单简易信息
            $('#dg').datagrid({
                url:"${proPath}/order/xian.action",
                checkbox: true,
                fitColumns:true,
                onClickRow: function (rowIndex, rowData) {
                // alert(rowData.orderNum)
                   ad(rowData.orderNum);//传订单号码查询
                },
                toolbar: [{
                    iconCls: 'icon-edit',
                    text:'单桌结算',
                    handler: function(){
                       var selectrow= $('#dg').datagrid('getSelected');
                       if(selectrow.payed==2){
                           //判断如果为2代表已经付款
                           $.messager.alert("提示");
                           $.messager.confirm('确认','还想给多一次钱吗？')
                         }else if (selectrow.orderState!=4){
                           //如果付款了 菜还没上不能进行付款
                           alert("菜还没上，客官别急，吃了再给钱")
                       }
                       else {
                             //以上条件都满足进入结算页面
                           parent.$('#win').window({
                               width:1000,
                               height:600,
                               modal:true,
                               content:"<iframe src='${proPath}/base/goURL.action?url=order/jiesuan' title='结算页面' height='100%' width='100%' frameborder='0px'/>"
                           });
                       }

                    }
                },'-',{
                    iconCls: 'icon-edit',
                    text:'整桌结算',
                    handler: function(){
                        var selectrow= $('#dg').datagrid('getSelected');
                        if(selectrow.payed==2){
                            //判断如果为2代表已经付款
                            $.messager.alert("提示");
                            $.messager.confirm('确认','还想给多一次钱吗？')
                        }else if (selectrow.orderState!=4){
                            //如果付款了 菜还没上不能进行付款
                            alert("菜还没上，客官别急，吃了再给钱")
                        }
                        else {
                        parent.$('#win').window({
                            width:1000,
                            height:600,
                            modal:true,
                            content:"<iframe src='${proPath}/base/goURL.action?url=order/Zhengjiesuan' title='结算页面' height='100%' width='100%' frameborder='0px'/>"
                            });
                        }
                    }
                },{
                    iconCls: 'icon-edit',
                    text:'打单',
                    handler: function(){
                        alert('新增订单')
                        parent.$('#win').window({
                            width:1000,
                            height:600,
                            modal:true,
                            content:"<iframe src='${proPath}/base/goURL.action?url=order/insertorder' title='结算页面' height='100%' width='100%' frameborder='0px'/>"
                        });
                    }
                },{
                    iconCls: 'icon-edit',
                    text:'整桌退单',
                    handler: function(){
                        var selectrow= $('#dg').datagrid('getSelected');

                        var refundsnum=(new Date()).valueOf();//生成退单号
                        alert(refundsnum);
                        var ordernum=selectrow.orderNum;//订单号；；
                        var deskid=selectrow.deskId;//桌号
                        var deskname=selectrow.deskName;//桌名字
                        var refundpay=selectrow.orderPay;//退单金额
                        var refundstime=selectrow.makeTime;//制单时间
                        var payform=selectrow.payFrom;//付款形式
                        var payed=selectrow.payed;//付款状态
                        alert(ordernum+deskid+deskname+refundpay+refundstime+payform+payed);
                        $.post(
                            "${proPath}/refunds/refundsinsert.action",
                            {   deskId:deskid,
                                deskName:deskname,
                                orderNum:ordernum,
                                refundsNum:refundsnum,
                                refundsPay:refundpay,
                                payForm:payform,
                                refundsState:4

                            },
                            function (data) {
                                alert("订单生成")
                                //修改订单状态
                            },
                            "json"
                        )
                    }
                }
                ],

                columns:[[
                    //表单数据详情列
                    {checkbox: true},
                    {field:'deskId',title:'餐桌ID',width:100},
                    {field:'deskName',title:'餐桌名称',width:100},
                    {field:'deskForm',title:'就餐形式',width:100},
                    {field:'orderNum',title:'订单号',width:100},
                    {field:'orderPay',title:'应付金额',width:100},
                    {field:'orderTruepay',title:'实付金额',width:100},
                    {field:'makeTime',title:'制单时间',width:200,  formatter:function(value,row,index){
                        var date = new Date(value);//把返回的数据转化成date类型数据
                        return myformatter(date);//调用转化格式function
                    } },
                    {field:'payTime',title:'结算时间',width:200, formatter:function(value,row,index){
                        var date = new Date(value);//把返回的数据转化成date类型数据
                        return myformatter(date);//调用转化格式function
                    } },
                    {field:'payed',title:'付款状态',width:100,formatter:rowformater},
                    {field:'orderState',title:'订单状态',width:100,formatter:rowformater1},
                    {field:'payFrom',title:'付款形式',width:100,align:'right'}
                 ]],
                striped:true,
                rownumbers:true,
                pagination:true,
                singleSelect:true,
                pageSize:5,
                pageList:[1,2,3,4,5],
            });

          })



            //转化时间格式function
      /*  function myformatter(date){
            var y = date.getFullYear();//获取年
            var m = date.getMonth()+1;//获取月
            var d = date.getDate();//获取日
            var h=date.getHours();//获取时
            var s=date.getSeconds();//获取秒
            //加入相关格式
            return y+"-"+(m<10?("0"+m):m)+"-"+(d<10?("0"+d):d)+"-"+(h<10?("0"+h):h)+":"+(s<10?("0"+s):s);
        }*/

        //转化付款转态function
        function rowformater(value, row, index) {
            // alert(value);
            if (value==1){
                value="未付款"
            }else if (value==2){
                value="已付款"
            }
              return value

        }
        //转化订单菜品转态function
        function rowformater1(value, row, index) {
           // alert(value);
            if (value==4){
                value="上菜了"
            }else if (value==3){
                value="做菜中"
            }
            else if(value==2){
             value="接单了"
             }else if(value==5){
                value="已完成"
            } else {
                 value="其他数值"
            }
            return value

        }

        //详细订单读取function
        function ad(a){
            $('#detail').datagrid({
                url:"${proPath}/order/detail.action",
                queryParams: {
                   simpleOrder: a
                },

                columns:[[
                    {checkbox: true},
                    {field:'orderNum',title:'订单号',width:100},
                    {field:'goodName',title:'商品名字',width:100},
                    {field:'goodExitNum',title:'商品数量',width:100},
                    {field:'goodPrice',title:'总价格',width:100},
                    {field:'orderState',title:'菜品状态',width:100,formatter:rowformater},
                    {field:'payForm',title:'付款形式',width:100},
                    {field:'deskId',title:'桌号',width:100,align:'right'},
                         ]],
                striped:true,
                rownumbers:true,
                pagination:true,
                pageSize:5,
                pageList:[1,2,3,4,5],
            });

            $('#tui').datagrid({
                url:"${proPath}/refunds/tuiming.action",
                queryParams: {
                    orderNum: a
                },

                columns:[[
                    {checkbox: true},
                    {field:'refundsNum',title:'退单号',width:100},
                    {field:'goodName',title:'商品名字',width:100},
                    {field:'goodNum',title:'退单数量',width:100},
                    {field:'goodPrice',title:'价格',width:100},
                    {field:'orderState',title:'菜品状态',width:100,formatter:rowformater},
                    {field:'deskName',title:'桌名字',width:100},
                    {field:'deskId',title:'桌号',width:100,align:'right'},
                ]],
                striped:true,
                rownumbers:true,
                pagination:true,
                pageSize:5,
                pageList:[1,2,3,4,5],
            });
        }
        //搜索function
        function test() {
            var compayid = $("#cc").find("option:selected").text();//获取公司名字
            var storename = $("#bm").find("option:selected").text();//商店名称
            var payform=$("#payform").find("option:selected").text();//商店名称
            var deskid = $("#deskId").val();
            var deskname = $("#deskName").val();
            var ordernum = $("#orderNum").val();
            var total = deskid + deskname + ordernum;
            if (total == null || total == '') {alert("没有填写信息")}
            else {
                $('#dg').datagrid('load', {
                    //注入搜索信息更新datagrid
                    deskId: deskid,
                    deskName: deskname,
                    orderNum: ordernum
                });

            }
        }
 </script>
</head>
<body>
<form method="POST" id="ff" >
公司名字：<select id="cc" class="easyui-combobox" name="conpanyId" style="width:200px;">
    <option value="aa">广宁集团</option>
    <option>浩明制药</option>
    <option>伟竹保健</option>

    </select>

部门名字：<select id="bm" class="easyui-combobox" name="storeName" style="width:200px;">
    <option value="aa">广宁广州分公司</option>
    <option>浩明广州制药厂</option>
    <option>伟竹保健广州分部</option>

</select>

餐桌号:<input type="text" value="" id="deskId"><br>
餐桌名字:<input type="text" value="" id="deskName">
原订单号:<input type="text" value="" id="orderNum">
<br>
付款方式：<select id="payform" class="easyui-combobox" name="payFrom" style="width:200px;">
    <option value="aa">微信</option>
    <option>支付宝</option>
    <option>信用卡或现金</option>
    <option>会员卡</option>
    </select><br>
<input type="button" onclick="test()">搜索
</form>



<table id="dg"
       data-options="singleSelect:false,checkOnSelect:false,fitColumns:true" >

</table>

<table id="detail"></table>
<table id="tui"></table>
<div id="win"></div>
</body>
</html>
